package feed;

class FeedLocation {
    def name;
    def link;
    def FeedLocation(n, l) { name = n; link = l; }
}

class Feed {
    def name; 
    def id; 
    def unread; 
    String toString() { 
        return (unread == "0" ? name : "${name} (${unread})");
    } 
}


class FeedService {
    def list = new java.util.ArrayList()
    def FeedService() {
        //TODO: search for all xmls in conf
        def url = "conf/rssreader/list.xml"

        def items = new XmlParser().parse(url).feeds[0].item

        for (item in items[0..<items.size()]) {
            list.add(new FeedLocation(item.title.text(), item.link.text()))
        }
    }
    def getFeedLocationList() { return list; }
    def fileForLink(link) { return "data/"+link.split("[?]")[0].replace(":","_").replace("/","_"); }
}

